package com.comsumer.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author
 * @name：
 * @data:
 * @className:
 **/
@Slf4j
@Component
public class consumer {
    /**
     * 延时队列消费者
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "delay.queue",declare = "true"),
            exchange = @Exchange(name = "delay.topic",type = "topic",delayed = "true"),
            key = "day"
    ))
    public void listenDelayExchange(String msg){
        log.info("消费者接收到了delay.topic的延迟消息:"+msg);

    }

    @RabbitHandler
    @RabbitListener(queues="direct.queue")
    public void process(String message)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("接收消息: " + message + " 接收时间：" + sdf.format(new Date()));
        throw new RuntimeException();
    }


}
